package mobileann.mafamily.utils;

import android.content.Context;
import mobileann.mafamily.act.main.FS;

public class LocationUtis {
	public static final String LOCTYPE = "locType";
	public static final int BASESTATION_LOCATE = 0; // 基站定位
	public static final int WIFI_LOCATE = 1; // wifi定位
	public static final int GPS_LOCATE = 2; // gps定位
	public static final int MOBILE_LOCATE = 3; // 移动网络定位
	public static final int OFFLINE_LOCATE = 4; // 离线定位
	public static final int UNKNOWN_LOCATE = -1; // 未知
	public static final int LOCATION_SERVER_DEFAULT = 15; // 服务器默认的, 先看作离线定位
	
	public static MapTag getInstance() {
		if (SPUtils.getMAPSDK().equals("AMap")) {
			// return GaodeLocationUtils.getInstance(FS.getInstance()); //
			// 暂时不用，要用也是二选一
			return BaiduLocationUtils.getInstance(FS.getInstance());
		} else {
			return BaiduLocationUtils.getInstance(FS.getInstance());
		}
	}

	public static void startWork(Context context, String flag){
		FS.locTag = flag;
		switch (NetUtils.getInstance().netstate()) {
		case 0:
			if(GPSUtils.getInstance(context).GPSOpen() && !SPUtils.getSavingMode()){
				GPSUtils.getInstance(context).startGPSSingle();
			}
//			else {
//				LocationUtis.getInstance().requestLocation(); // 离线状态线为了获得离线定位 &ADRIAN.2015.7.31.15.37
//			}
			break;
		case 1:
			if(!SPUtils.getSavingMode() && NetUtils.getInstance().hasMobileConnected()
					&& GPSUtils.getInstance(context).GPSOpen()
					&& SPUtils.getFristRecordSucceed()
					&& !FS.gpsWroking){
				GPSUtils.getInstance(context).startGPSSingle();
			}else{
				LocationUtis.getInstance().requestLocation();
			}
			break;
		case 2:
			LocationUtis.getInstance().requestLocation();
			break;
		default:
			break;
		}
	}


	/**
	 * 主要功能:// 0：基站, 1: WiFi，2：GPS
	 * <br> 0. 基站
	 * <br> 1. WIFI
	 * <br> 2. GPS定位
	 * <br> 3. 移动网络定位
	 * <br> 4. 离线定位
	 * <br> -1 unknown
	 */
	public static String locateMode(int mode){
		if (mode == BASESTATION_LOCATE || mode == MOBILE_LOCATE) {
			return "移动网络定位";
		} else if(mode  ==  WIFI_LOCATE) {
			return "WIFI定位";
		} else if(mode == GPS_LOCATE) {
			return "GPS定位";
		} else if(mode == LOCATION_SERVER_DEFAULT || mode == OFFLINE_LOCATE) {
			return "离线定位";
		} else if(mode == UNKNOWN_LOCATE){
			return ""; // unknown
		} else {
			return "";
		}
	}

}
